<?php

namespace App\Http\Controllers\Api;

use App\Http\Services\RemindService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

/**
 * @property RemindService $remindService
 */
class WxRemindController extends BaseController
{
    public function __construct(RemindService $remindService)
    {
        $this->remindService = $remindService;
    }

    public function addRemind(Request $request)
    {
        $post = $request->post();
        $validator = Validator::make($post, [
            'memos_id' => 'required|unique:wechat_reminders,memos_id',
        ], [
            'memos_id.required' => '标题不能为空',
            'memos_id.unique' => '已经添加过提醒了呦~',
        ]);
        if ($validator->fails()) {
            return $this->fail($validator->errors()->first());
        }

        $result = $this->remindService->addRemind($request->post());
        if (!$result) {
            return $this->fail('添加失败');
        }
        return $this->success();
    }

    public function remindList(Request $request)
    {
        return $this->success($this->remindService->getList($request->all()));
    }

    public function deleteRemind(Request $request)
    {
        $result = $this->remindService->deleteRemind($request->get('id', 1));
        if (!$result) {
            return $this->fail('删除失败');
        }
        return $this->success();
    }
}
